<template>
	<view class="content">
		<view class="topbar">
			<view class="back" @tap="back()">
				<image src="../../static/image/search/back.png" mode=""></image>
			</view>
		</view>
		<view class="title">
			<view class="songname">
				{{this.audiolist[this.curindex].songname}}
			</view>
			<view class="artist">
				{{this.audiolist[this.curindex].artistname}}
			</view>
		</view>
		<view class="main">
			<view class="btn">
				<image class="left" @tap="before()" src="../../static/image/player/left.png" mode=""></image>
				<view class="box" >
					<view class="one">
						<view class="two" @tap="play()">
							<image :src="this.curimg" mode=""></image>
						</view>
					</view>
				</view>
				<image class="right" @tap="next()" src="../../static/image/player/right.png" mode=""></image>
			</view>
			<view class="btn2">
				<image v-if="!audiolist[curindex].like" @tap="likes()" class="dontlike img" src="../../static/image/player/love.png" mode=""></image>
				<image v-if="audiolist[curindex].like" @tap="dontlikes()" class="like img" src="../../static/image/index/love.png" mode=""></image>
				<image v-if="!single" @tap="singles()" class="single img" src="../../static/image/player/single.png" mode=""></image>
				<image v-if="single" @tap="alls()" class="all img" src="../../static/image/player/all.png" mode=""></image>
				<image class="comment img" @tap="showCard()" src="../../static/image/player/comment.png" mode=""></image>
			</view>
		</view>
		<view class="lyric-box">
			<view class="ric">风雨里追赶</view>
			<view class="ric cur">雾里分不清影踪</view>
			<view class="ric">天空海阔你与我</view>
		</view>
		<view class="card" :animation="animationData">
			<image class="hid" src="../../static/image/search/back.png" mode="" @tap="showCard()"></image>
			<view class="bg">
				<image src="../../static/image/test/1.jpg"></image>
			</view>
			<view class="list">
				<view class="name" style="
				border-bottom:1rpx solid #fff;
				font-size: 34rpx;
				font-weight: 550;
				padding: 20rpx ;
				">
					全部评论
				</view>
				<view class="listrow" v-for="(item,index) in comments" :key='index'>
					<view class="top">
						<view class="name">
							{{item.nickname}}
						</view>
						<view class="time">
							{{item.time}}
						</view>
					</view>
					<view class="texts">
						{{item.content}}
					</view>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
	import request from '../../utils/request.js'
	import timer from '../../utils/timer.js'
	import {
		mapGetters,
		mapMutations
	} from 'vuex'
	import Vue from 'vue'
	export default {
		data() {
			return {
				likelist:[],
				like: false,
				single: false,
				comments: [],
				showComment: false,
				animationData: {},
				songid:346089,
				plays:false,
				hidwidth:0,
			};
		},
		onLoad() {
			
		},
		onReady() {
			this.getElementStyle()
			// this.isLike();
		},
		computed: {
			...mapGetters(['curimg', 'curindex', 'audiolist']),
		},
		methods: {
			//跳转到主页
			back: function() {
				uni.navigateTo({
					url: '../index/index'
				});
			},
			
			//获取设备信息
			getElementStyle: function(){
				const query = uni.createSelectorQuery().in(this);
				query.select('.content').boundingClientRect(data=>{
					// console.log("得到布局位置信息："+JSON.stringify(data));
					// console.log("节点离页面顶部的高度为："+data.top);
					this.hidwidth = data.width+10;
				}).exec();
			},

			//获取歌曲评论
			showCard: function() {
				this.comments = []
				this.showComment = !this.showComment;
				//发送请求
				uni.request({
					url:'https://qqyifeng.cn:9001/comment/music',
					data: {
						id:this.songid,
						limit:50,
						offset:0
					},
					method:'GET',
					success: (res) => {
						// let result = JSON.stringify(res);
						res.data.comments.forEach((item,index)=>{
							let nickname = item.user.nickname;
							let content = item.content;
							let time = timer.timer(item.time);
							
							this.comments.push({
								nickname,
								content,
								time
							});
						})
					}
				});
				// console.log(this.comments)
				//设置动画
				var animation = uni.createAnimation({
					duration: 300,
					timingFunction: 'ease',
				});
				if(this.showComment){
					animation.right(0).step();
				}
				else{
					animation.right(-this.hidwidth).step();
				}
				this.animationData = animation.export();
			},
			
			//首先查看此歌是否位于我的歌单列表
			// isLike: function(){
			// 	try {
			// 	    this.likelist = uni.getStorageSync('mylist');
			// 	} catch (e) {
			// 	    uni.showToast({
			// 	    	icon:"none",
			// 			title:"获取我的歌单失败"
			// 	    })
			// 	}
			// 	for(let i=0;i<this.likelist.length;i++){
			// 		if(this.audiolist[this.curindex].id == this.like[i].id){
			// 			this.like == true;
			// 		}
			// 	}
			// },
		
			//收入我的歌单
			likes: function(){
				if(this.like){
					//取消喜欢
					let list = uni.getStorageSync('likelist');
					for (let i=0;i<list.length;i++) {
						if(this.audiolist[this.curindex].id == list[i].id){
							list.splice(i,1);
						}
					}
					uni.setStorageSync('likelist',list);
					let audiolists = this.audiolist;
					audiolists[curindex].like = false;
					this.setAudiolist(audiolists);
					console.log(this.audiolist);
					uni.showToast({
						icon:'none',
						title:'已从歌单移除'
					})
				}else{
					//加入我喜欢
					let list = []
					list = uni.getStorageSync('likelist');
					if(list == ""){list =[]}
					list.push(this.audiolist[this.curindex])
					uni.setStorageSync('likelist',list);
					this.like = true;
					uni.showToast({
						icon:'none',
						title:'已添加进歌单'
					})
					list = uni.getStorageSync('likelist');
					console.log(list);
				}
				// console.log("now like");
			},
			
			//从我的歌单中移除
			dontlikes: function(){
				this.like = false;
				console.log("now do not like");
			},
			
			//单曲循环
			singles: function(){
				this.single = true;
				console.log("now single play");
			},
			
			//顺序循环
			alls: function(){
				this.single = false;
				console.log("now not single play");
			},
			
			//前一首
			before: function(){
				console.log("上一首")
			},
			
			//下一首
			next: function(){
				console.log("下一首")
			},
			
			//暂停播放
			play: function(){
				console.log("暂停/播放")
				this.plays = !this.plays;
				if(this.plays){
					Vue.prototype.$au_player.pause();
				}else{
					Vue.prototype.$au_player.play();
				}
			}
			
		}
	}
</script>

<style lang="scss">
	.content {
		width: 100%;
		height: 100%;
		box-sizing: border-box;
		background-attachment: fixed;
		padding: $uni-spacing-row-sm 10rpx;
		// padding-top: var(--status-bar-height);
		// bottom: env(safe-area-inset-bottom);

		.topbar {
			display: flex;
			width: 100%;
			height: 72rpx;
			padding-bottom: 20rpx;
			// border-bottom: 1rpx solid #F1F1F1;

			image {
				width: 60rpx;
				height: 60rpx;
			}

			.back {
				felx: 1;
				display: flex;
				justify-content: center;
				align-items: center;
				text-align: center;
			}
		}

		.title {
			width: 100%;
			box-sizing: border-box;
			padding: 60rpx 30rpx;

			.songname {
				margin: 0 auto;
				font-size: 42rpx;
				width: 80%;
				text-align: center;
				color: #666;
				font-weight: 550;
				display: -webkit-box !important;
				text-overflow: ellipsis;
				overflow: hidden;
				-webkit-line-clamp: 1;
				-webkit-box-orient: vertical;
			}

			.artist {
				margin: 0 auto;
				text-align: center;
				width: 80%;
				color: #C0C0C0;
				display: -webkit-box !important;
				text-overflow: ellipsis;
				overflow: hidden;
				-webkit-line-clamp: 1;
				-webkit-box-orient: vertical;
			}
		}

		.main {
			height: 50%;
			padding: 30rpx 0;

			.btn {
				display: flex;
				justify-content: center;
				align-items: center;

				.left {
					flex: 1;
					width: 60rpx;
					height: 140rpx;
				}

				.box {
					flex: 5;
					display: flex;
					justify-content: center;
					align-items: center;

					.one {
						display: flex;
						justify-content: center;
						align-items: center;
						width: 420rpx;
						height: 420rpx;
						border-radius: 50%;
						background-color: #F1F1F1;
						box-shadow: 0 0 20rpx #C8C7CC;

						.two {
							display: flex;
							justify-content: center;
							align-items: center;
							width: 350rpx;
							height: 350rpx;
							border-radius: 50%;
							background-color: #C0C0C0;

							image {
								width: 300rpx;
								height: 300rpx;
								border-radius: 50%;
							}
						}
					}
				}

				.right {
					flex: 1;
					width: 60rpx;
					height: 140rpx;
				}
			}

			.btn2 {
				padding-top: 60rpx;
				justify-content: space-around;
				display: flex;

				.img {
					width: 60rpx;
					height: 60rpx;
				}

				.like {}

				.comment {}
			}

		}

		.lyric-box {
			padding-top: 30rpx;
			width: 100%;
			text-align: center;
			display: flex;
			flex-direction: column;

			.ric {
				margin: 10rpx 0;
				font-size: 32rpx;
				color: #999;
			}

			.cur {
				color: #515151;
			}
		}

		.card {
			z-index: 998;
			background-color: #fff;
			width: 100%;
			height: 50%;
			position: fixed;
			top: 50%;
			right: -170%;
			overflow: hidden;

			// left: -170%;
			.hid {
				position: absolute;
				top: 10rpx;
				z-index: 999;
				display: flex;
				justify-content: center;
				align-items: center;
				text-align: center;
				width: 60rpx;
				height: 60rpx;
			}

			.bg {
				top: -50rpx;
				left: -50rpx;
				width: 100%;
				position: relative;
				filter: blur(10px);

				image {
					opacity: 0.5;
					position: absolute;
					width: 150%;
				}
			}

			.list {
				z-index: 999;
				width: 90%;
				height: 85%;
				margin: 80rpx auto;
				background-color: #C0C0C0;
				border-radius: 32rpx 32rpx 0 0;
				padding: 12rpx 24rpx;
				overflow-y: auto;

				.listrow {
					z-index: 999;
					height: 120rpx;
					line-height: 42rpx;
					overflow: hidden;
					border-bottom: 1rpx solid #fff;
					padding: $uni-spacing-row-base 0;

					.top {
						z-index: 999;
						display: flex;
						padding: 0 10rpx;

						.name {
							flex: 3;
							padding-left: 20rpx;
							font-size: 30rpx;
							font-weight: 550;
							color: #000;
							display: -webkit-box !important;
							text-overflow: ellipsis;
							overflow: hidden;
							-webkit-line-clamp: 1;
							-webkit-box-orient: vertical;
						}

						.time {
							z-index: 999;
							width: 200rpx;
							float: right;
							flex: 1;
							color: #555;
							font-size: 30rpx;
							display: -webkit-box !important;
							text-overflow: ellipsis;
							overflow: hidden;
							-webkit-line-clamp: 1;
							-webkit-box-orient: vertical;
						}
					}

					.texts {
						z-index: 999;
						padding: 10rpx 30rpx;
						font-size: 28rpx;
						display: -webkit-box !important;
						color: #555;
						text-overflow: ellipsis;
						overflow: hidden;
						-webkit-line-clamp: 2;
						-webkit-box-orient: vertical;
					}

				}
			}
		}
	}
</style>
